﻿using NDF.Collections;
using NDF.Collections.Generic;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace System.Collections
{
    /// <summary>
    /// 提供一组针对 <see cref="System.Collections.IEqualityComparer"/> 接口的常用工具方法扩展。
    /// </summary>
    public static class IEqualityComparerExtensions
    {
        /// <summary>
        /// 将普通对象比较器 <see cref="System.Collections.IEqualityComparer"/> 转换成支持泛型操作的 <see cref="System.Collections.Generic.IEqualityComparer(object)"/> 对象。
        /// </summary>
        /// <param name="comparer">被转换的 <see cref="System.Collections.IEqualityComparer"/> 对象。</param>
        /// <returns>一个支持泛型操作的 <see cref="System.Collections.Generic.IEqualityComparer(object)"/> 对象，该对象等效于源对象 comparper。</returns>
        public static IEqualityComparer<object> ToGeneric(this IEqualityComparer comparer)
        {
            return GenericEqualityComparer<object>.Create((a, b) => comparer.Equals(a, b), a => comparer.GetHashCode(a));
        }
    }
}
